'use strict';

/**
 * @name 莫凡淘宝 2.0 后端 参数验证
 * @version 1.0.0
 * @author xiech
 * @Time 2019年10月30日14:55:14
 */

const Joi = require('joi');

module.exports = async (schema, data) => {
	return new Promise((resolve, reject) => {
		let result = Joi.validate(data, schema);
		if(result.error){
			let error = result.error;
			error.msg = "parameter error!";
			error.code = 7000;
			reject(error);
		}else{
			resolve("ok");
		}
	});
}
